﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD;
using Xunit;

namespace DokiDokiTest {
    public class TestAnimationTrack {
        [Fact]
        public void Test_New1 () {
            var kseq = new KeyframeSequence<float> (4, 3);
            var track = new AnimationTrack (kseq, "Hello world");

            Assert.Equal (1, track.KeyframeSequenceCount);
            Assert.Equal (kseq, track.GetKeyframeSequence(0));
            Assert.Equal ("Hello world", track.TargetProperty);
        }

        [Fact]
        public void Test_New2 () {
            var kseq1 = new KeyframeSequence<float> (4, 3);
            var kseq2 = new KeyframeSequence<float> (4, 3);
            var track = new AnimationTrack (new[]{kseq1, kseq2}, "Hello world");

            Assert.Equal (2, track.KeyframeSequenceCount);
            Assert.Equal (kseq1, track.GetKeyframeSequence(0));
            Assert.Equal (kseq2, track.GetKeyframeSequence (1));
            Assert.Equal ("Hello world", track.TargetProperty);
        }

        [Fact]
        public void Test_Eumerator () {
            var kseq1 = new KeyframeSequence<float> (4, 3);
            var kseq2 = new KeyframeSequence<float> (4, 3);
            var track = new AnimationTrack (new[] { kseq1, kseq2 }, "Some Property");

            var sum = track.KeyframeSequences.Sum (x => 1);

            Assert.Equal (2, sum);
        }

        [Fact]
        public void Test_References () {
            var kseq1 = new KeyframeSequence<float> (4, 3);
            var kseq2 = new KeyframeSequence<float> (4, 3);
            var track = new AnimationTrack (new[] { kseq1, kseq2 }, "Some Property");

            var objs = track.References;

            Assert.Equal (2, objs.Count ());
            Assert.Equal (true, objs.All (x => x != null));
        }

        [Fact]
        public void Test_Find () {
            var kseq1 = new KeyframeSequence<float> (4, 3);
            var kseq2 = new KeyframeSequence<float> (4, 3);
            var track = new AnimationTrack (new[] { kseq1, kseq2 }, "Some Property");

            kseq1.UserID = 101;

            Assert.Equal (kseq1, track.Find(101));
        }
        
        [Fact(Skip="未実装")]
        public void Test_Sample () {
            var kseq = new KeyframeSequence<float> (4, 1);
            kseq.SetKeyframe (0, 0, 0);
            kseq.SetKeyframe (1, 100, 100);
            kseq.SetKeyframe (2, 200, 200);
            kseq.SetKeyframe (3, 300, 300);
            kseq.SetInterpolationMode (InterpolationType.Linear);
            kseq.SetDuration (300);

            var track = new AnimationTrack (kseq, "Hello world");
            var clip = new AnimationClip ();
            clip.AddTrack (track);

            var value = new float[1];
            track.Sample (150, value);

            Assert.Equal (150, value[0], new FloatComparer (0.0001f));
        }


    }
}
